package com.ll.homework;

/**
 * @author 刘龙
 * @version 1.0
 */
public class StringHomework02 {
    public static void main(String[] args) {
        try {
            String abc_def_ghi = printName("abc def ghi");
            // ghi,abc .D
            System.out.println(abc_def_ghi);
        } catch (RuntimeException e) {
            System.out.println(e.getMessage());
        }
    }

    public static String printName(String str) {
        if (str == null || str == " ") {
            throw new RuntimeException("字符串不能为空");
        }

        String[] names = str.split(" ");
        if (names.length != 3) {
            throw new RuntimeException("输入的字符串格式不对,正确格式:xx xx xx");
        }

        String format = String.format("%s,%s .%c", names[2], names[0], names[1].toUpperCase().charAt(0));

        return format;
    }
}
